package com.gitee.sliu.binlog5j.core;

import com.gitee.sliu.binlog5j.core.config.RedisConfig;
import com.gitee.sliu.binlog5j.core.enums.BinlogClientMode;
import com.gitee.sliu.binlog5j.core.position.BinlogPositionHandler;
import com.gitee.sliu.binlog5j.core.utils.MD5Utils;
import com.zaxxer.hikari.HikariConfig;
import lombok.Data;

import java.util.concurrent.TimeUnit;

/**
 * Binlog Client 配置
 *
 * @author SLIU
 */
@Data
public class BinlogClientConfig {

    /**
     * 账户
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 地址
     */
    private String host;

    /**
     * 端口
     */
    private int port = 3306;

    /**
     * 时间偏移量
     */
    private long timeOffset = 0;

    /**
     * 客户端编号 (不同的集群)
     */
    private long serverId;

    /**
     * 是否保持连接
     */
    private Boolean keepAlive = true;

    /**
     * 是否是首次启动
     */
    private Boolean inaugural = false;

    /**
     * 保持连接时间
     */
    private long keepAliveInterval = TimeUnit.MINUTES.toMillis(1L);

    /**
     * 连接超时时间
     */
    private long connectTimeout = TimeUnit.SECONDS.toMillis(3L);

    /**
     * 发送心跳包时间间隔
     */
    private long heartbeatInterval = TimeUnit.SECONDS.toMillis(6L);

    /**
     * “分布式” “记忆读取”
     * <p>
     * 依赖的 Redis 中间件配置
     */
    private RedisConfig redisConfig;

    /**
     * 读取记忆
     */
    private Boolean persistence = false;

    /**
     * 严格模式
     *
     * 性能与健壮性的平衡
     * */
    private Boolean strict = true;

    /**
     * 部署模式
     */
    private BinlogClientMode mode = BinlogClientMode.standalone;

    /**
     * 持久化 PositionHandler 实现 (优先级 > RedisConfig)
     * */
    private BinlogPositionHandler positionHandler;

    private HikariConfig hikariConfig;

    public String getKey() {
        return MD5Utils.encrypt(this.host + ":" + this.port + ":" + this.serverId);
    }
}
